package mymail;

import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;

import com.sun.mail.imap.IMAPFolder;

public class IMAP {
    public static Folder getFolder(String host, String username, String password) {
        Properties prop = new Properties();
        prop.setProperty("mail.store.protocol", "imap");
        prop.setProperty("mail.imap.host", host);
        prop.put( "mail.smtp.auth ", "true ");
        prop.put("MAIL.IMAP.AUTH.PLAIN.DISABLE","TRUE");
        prop.setProperty("mail.imap.auth.login.disable", "true");

        Session mailSession = Session.getDefaultInstance(prop, null);
        mailSession.setDebug(false);

        try {
            Store store = mailSession.getStore("imap");
            store.connect(host, username, password);
            Folder folder =(IMAPFolder) store.getFolder("Sent");
            folder.open(Folder.READ_WRITE);
            return folder;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

